﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataTransferObjects;
using System.Xml;

namespace DataAccessObject
{
    public class AccountAndKeyDAO
    {
        static public void exportAccountAndKeyToFile(String strFilePath, AccountAndKeyDTO accountAndKey)
        {
            string a= strFilePath+".xml"
            FileStream fs = new FileStream(a, FileMode.Create);
            XmlTextWriter w = new XmlTextWriter(fs, Encoding.UTF8);

            w.WriteStartDocument();
            w.WriteStartElement("UserInfor");
            w.WriteStartElement("User");
            w.WriteElementString("id", accountAndKey.iUserID);
            w.WriteElementString("UserName",accountAndKey.strName );
            w.WriteElementString("Birthday", accountAndKey.birthday);
            w.WriteElementString("Phone", accountAndKey.phoneNumber);
            w.WriteElementString("Address",accountAndKey.address);
            w.WriteElementString("Email", accountAndKey.email);
            w.WriteElementString("Hash", accountAndKey.hashValue);
            w.WriteElementString("KeyLength",accountAndKey.keyLength);
            w.WriteElementString("rsaD",accountAndKey.rsaD);
            w.WriteElementString("rsaExponent",accountAndKey.rsaExponent);
            w.WriteElementString("rsaModulus",accountAndKey.rsaModulus);
            w.WriteElementString("saltValue",accountAndKey.saltValue);
            w.WriteEndElement();

            w.WriteEndElement();
            w.WriteEndDocument();
            w.Flush();
            fs.Close();         

        }

        public static void importAccountAndKeyFromFile(string strFilePath)
        {
            //Đọc nội dung dữ liệu từ tập tin

            //Sau đó import vào CSDL.

            //Giá trị trả về cho biết có bị lỗi đọc tập tin hay không

            FileStream fs = new FileStream(strFilePath, FileMode.Open);
            XmlTextReader r = new XmlTextReader(fs);
            string a[15];int i=0;
            while (r.Read()) {
 
           if (r.NodeType == XmlNodeType.Element) {

                
                if (r.HasAttributes) {

   /                 for (int i = 0; i < r.AttributeCount; i++) {
                         string c= r.GetAttribute(i);
                    }
                }
            }
            else if (r.NodeType == XmlNodeType.Text) {
               string a[i++]= r.Value;
            }
        }
        Console.ReadLine();
    }
}
            
        }
    
}
